package org.grow.present.controller;

import org.grow.present.domain.Company;
import org.grow.present.dto.Dict;

import org.grow.present.dto.Msg;
import org.grow.present.mapper.CompanyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: xwg
 * @CreateDate: 2024/6/5
 */

@RestController
@RequestMapping("/tool")
public class ToolController {
@Autowired
private CompanyMapper companyMapper;
    @GetMapping("/dicts")
    public Msg<List<Dict>> getDicts() {
       List<Dict> dicts = new ArrayList<>(20);
        List<Company> companies = companyMapper.selectList(null);
        List<Dict> dicts3 = companies.stream().map(c -> {
            Dict dict = new Dict();
            dict.setLabel(c.getComName());
            dict.setValue(c.getComId().toString());
            dict.setType("Company");
            dict.setColor(c.getComStatus());
            return dict;
        }).collect(Collectors.toList());
        dicts.addAll(dicts3);

        return Msg.success().data(dicts);
    }
}
